const api = require('../../utils/api.js');

Page({
  data: {
    faqList: []
  },

  onLoad() {
    // 页面加载时获取FAQ列表
    this.loadFAQList();
  },

  // 加载FAQ列表
  async loadFAQList() {
    try {
      const response = await api.getFAQList();
      // 为每个FAQ项添加expanded属性
      const faqList = (response.faqs || []).map(faq => ({
        ...faq,
        expanded: false
      }));
      
      this.setData({
        faqList: faqList
      });
    } catch (error) {
      console.error('获取FAQ列表失败:', error);
      wx.showToast({
        title: '获取FAQ列表失败',
        icon: 'none'
      });
    }
  },

  // 切换FAQ展开状态
  toggleFAQ(e) {
    const index = e.currentTarget.dataset.index;
    const faqList = this.data.faqList;
    faqList[index].expanded = !faqList[index].expanded;
    
    this.setData({
      faqList: faqList
    });
  }
});